package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.ZhengnianlianxiMapper;
import com.example.xinli.dao.ZidongsiweiMapper;
import com.example.xinli.domain.entity.Zhengnianlianxi;
import com.example.xinli.domain.entity.Zidongsiwei;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.domain.vo.ZhengnianlianxiSubmitVo;
import com.example.xinli.domain.vo.ZidongsiweiSubmitVo;
import com.example.xinli.service.IZhengnianlianxiService;
import com.example.xinli.service.IZidongsiweiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ZhengnianlianxiServiceImpl extends ServiceImpl<ZhengnianlianxiMapper, Zhengnianlianxi> implements IZhengnianlianxiService {

    @Autowired
    ZhengnianlianxiMapper zhengnianlianxiMapper;

    @Override
    public ResponseBean getAllUserZhengnianlianxi(String userId) {
        QueryWrapper<Zhengnianlianxi> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Zhengnianlianxi> zhengnianlianxiList = zhengnianlianxiMapper.selectList(queryWrapper);
        return ResponseBean.success(zhengnianlianxiList);
    }

    @Override
    public ResponseBean submitZhengnianlianxi(ZhengnianlianxiSubmitVo zhengnianlianxiSubmitVo) {
        Zhengnianlianxi zhengnianlianxi = new Zhengnianlianxi();
        zhengnianlianxi.setUserId(zhengnianlianxiSubmitVo.getUserId());
        zhengnianlianxi.setDate(zhengnianlianxiSubmitVo.getDate());
        zhengnianlianxi.setQingjing(zhengnianlianxiSubmitVo.getQingjing());
        zhengnianlianxi.setGanshou(zhengnianlianxiSubmitVo.getGanshou());
        zhengnianlianxi.setBianhua(zhengnianlianxiSubmitVo.getBianhua());
        zhengnianlianxi.setQingxu(zhengnianlianxiSubmitVo.getQingxu());
        zhengnianlianxi.setZenyang(zhengnianlianxiSubmitVo.getZenyang());
        zhengnianlianxi.setRecordId(-1);

        int res = zhengnianlianxiMapper.insert(zhengnianlianxi);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

